OpenRoads Designer CONNECT Edition SDK Help

Auto create different named boundary groups based on chainage of applied templates

The below code snippet shows how to create named boundaries and groups based on start and end chainage of applied corridor templates. User might need unit conversion for the points used for named boundary creation based on unit settings.



//Required References

using Bentley.GeometryNET;
using Bentley.DgnPlatformNET;
using Bentley.MstnPlatformNET;
using System.Collections.Generic;
using Bentley.CifNET.GeometryModel.SDK;
using Bentley.CifNET.LinearGeometry;

   public void AutoCreateNBGroupBasedOnChainageOfAppliedTemplates()
        {
            DgnModel model = Session.Instance.GetActiveDgnModel();

            Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit con = Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit.GetActive();
            GeometricModel geomModel = con.GetActiveGeometricModel();
            if (geomModel == null) return;

            int count = 1;
            //Create named boundary for first corridor from DGN file 
            foreach (Corridor corridor in geomModel.Corridors)
            {

                IEnumerable<TemplateDrop> templateDrops = corridor.TemplateDrops;
                foreach (TemplateDrop templateDrop in templateDrops)
                {
                    //Get points at distance offset for named boundary creation based on start distance and end distance of applied template
                    LinearPoint point1 = corridor.CorridorAlignment.LinearGeometry.GetPointAtDistanceOffset(templateDrop.StartDistance, 50);
                    LinearPoint point2 = corridor.CorridorAlignment.LinearGeometry.GetPointAtDistanceOffset(templateDrop.StartDistance, -50);
                    LinearPoint point3 = corridor.CorridorAlignment.LinearGeometry.GetPointAtDistanceOffset(templateDrop.EndDistance, -50);
                    LinearPoint point4 = corridor.CorridorAlignment.LinearGeometry.GetPointAtDistanceOffset(templateDrop.EndDistance, 50);
                    LinearPoint point5 = point1;


                    //User might need unit conversion hereon points based on Unit settings in DGN file
                    DPoint3d[] nbPoints = new DPoint3d[5];
                    nbPoints[0] = point1.Coordinates;
                    nbPoints[1] = point2.Coordinates;
                    nbPoints[2] = point3.Coordinates;
                    nbPoints[3] = point4.Coordinates;
                    nbPoints[4] = point5.Coordinates;


                    //Create new Shape Element from points
                    Bentley.DgnPlatformNET.Elements.ShapeElement nbShape = new Bentley.DgnPlatformNET.Elements.ShapeElement(model, null, nbPoints);

                    //Add newly created shape to the Active Dgn Model
                    nbShape.AddToModel();

                    //Create new instance of Named Boundary object and add shape as graphical element to NB 
                    NamedBoundary namedBoundary = new NamedBoundary();
                    namedBoundary.Name = "NamedBoundary" + count;
                    namedBoundary.ModelRef = model;
                    namedBoundary.GraphicalElement = nbShape;

                    //Save Named Boundary
                    if (StatusInt.Success != namedBoundary.Save())
                        return;

                    //Create new Named Boundary Group
                    NamedBoundaryGroup nbGroup = Bentley.DgnPlatformNET.NamedBoundaryGroup.CreateNamedBoundaryGroup(model, "NbGroup" + count, "NbGroup" + count);

                    //Insert Named Boundary in Named Boundary Group
                    nbGroup.InsertBoundary(namedBoundary);

                    //Write Named Boundary Group to file
                    if (StatusInt.Success != nbGroup.WriteToFile())
                        return;

                    count++;
                }
                break;
            }
        }

Output